using HKB.Common;
using System;
using System.Data;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Xml;
namespace HKB.Web
{
	public class HoWave_Root : Page
	{
		private string _AppPrefix = AppSetings.Get("AppPrefix");
		private string _InstallDir = AppSetings.Get("InstallDir");
		private string _m_ShopDir = AppSetings.Get("m_ShopDir");
		private Conn _conn;
		private DataRow _config = null;
		protected virtual string AppPrefix
		{
			get
			{
				return this._AppPrefix;
			}
		}
		protected virtual string InstallDir
		{
			get
			{
				return this._InstallDir;
			}
		}
		protected virtual string m_ShopDir
		{
			get
			{
				return this._m_ShopDir;
			}
		}
		protected virtual Conn conn
		{
			get
			{
				Conn conn;
				if (this._conn == null)
				{
					try
					{
						this._conn = new Conn();
					}
					catch (Exception ex)
					{
						HttpContext.Current.Response.Write(Language.Get("Common/ConnErr") + ex.Message.ToString());
						HttpContext.Current.Response.End();
					}
					conn = this._conn;
				}
				else
				{
					conn = this._conn;
				}
				return conn;
			}
		}
		protected virtual DataRow config
		{
			get
			{
				DataRow config;
				if (this._config == null)
				{
					try
					{
						this._config = new Config().config;
					}
					catch (Exception ex)
					{
						HttpContext.Current.Response.Write(ex.Message.ToString());
						this.Finish();
						HttpContext.Current.Response.End();
					}
					config = this._config;
				}
				else
				{
					config = this._config;
				}
				return config;
			}
		}
		public HoWave_Root()
		{
			base.Error += new EventHandler(this.Root_Error);
		}
		protected virtual void Finish()
		{
			if (null != this._conn)
			{
				if (this._conn.Connected)
				{
					this._conn.CloseConn();
					this._conn = null;
				}
			}
		}
		protected virtual string Md5(string str)
		{
			return FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
		}
		protected virtual string Md5(string str, int n)
		{
			string text = FormsAuthentication.HashPasswordForStoringInConfigFile(str, "MD5").ToLower();
			string result;
			if (n == 32)
			{
				result = text;
			}
			else
			{
				if (n == 16)
				{
					result = text.Substring(8, 16);
				}
				else
				{
					result = null;
				}
			}
			return result;
		}
		protected virtual string HTMLEncode(string str)
		{
			StringBuilder stringBuilder = new StringBuilder(str);
			stringBuilder.Replace("&", "&amp;");
			stringBuilder.Replace("<", "&lt;");
			stringBuilder.Replace(">", "&gt;");
			stringBuilder.Replace("\"", "&quot;");
			stringBuilder.Replace("'", "&#39;");
			stringBuilder.Replace("\t", "&nbsp; &nbsp; ");
			stringBuilder.Replace("\r", "");
			stringBuilder.Replace("\n", "<br />");
			return stringBuilder.ToString();
		}
		protected virtual string MakeOutTradeNo()
		{
			Random random = new Random();
			return (10 + random.Next(9999999)).ToString();
		}
		protected virtual string MakePassword()
		{
			string text = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			string text2 = "";
			int num = 8;
			Random random = new Random();
			for (int i = 0; i < num; i++)
			{
				int index = random.Next(text.Length);
				text2 += text[index];
			}
			return text2;
		}
		protected virtual string MakePassword(int pwdlen)
		{
			string text = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			string text2 = "";
			Random random = new Random();
			for (int i = 0; i < pwdlen; i++)
			{
				int index = random.Next(text.Length);
				text2 += text[index];
			}
			return text2;
		}
		protected virtual bool ProcessSqlStr(string Str)
		{
			bool result = true;
			try
			{
				if (Str != "")
				{
					string text = "exec|insert|select|delete|update|count|*|chr|mid|master|truncate|char|declare|'|;";
					string[] array = text.Split(new char[]
					{
						'|'
					});
					string[] array2 = array;
					for (int i = 0; i < array2.Length; i++)
					{
						string value = array2[i];
						if (Str.IndexOf(value) >= 0)
						{
							result = false;
						}
					}
				}
			}
			catch
			{
				result = false;
			}
			return result;
		}
		protected virtual string HtmlReplace(string Str)
		{
			return Regex.Replace(Str, "<w>", "");
		}
		private string ReplaceBadChar(string strChar)
		{
			string text = "";
			string result;
			if (strChar == "" || string.IsNullOrEmpty(strChar))
			{
				result = text;
			}
			else
			{
				strChar = this.HTMLEncode(strChar);
				result = strChar;
			}
			return result;
		}
		protected virtual bool CheckNameLength(string Name, int Min, int Max)
		{
			bool result;
			if (Name != "")
			{
				int strLen = this.GetStrLen(Name);
				result = (strLen <= Max && strLen >= Min);
			}
			else
			{
				result = false;
			}
			return result;
		}
		private int GetStrLen(string ss)
		{
			string arg = "";
			char[] array = ss.ToCharArray();
			int num = ss.Length;
			int result;
			if ("恒浪".Length == 4)
			{
				result = num;
			}
			else
			{
				for (int i = 0; i < array.Length; i++)
				{
					if (Convert.ToInt32(array[i]) > 255)
					{
						num++;
						arg += array[i];
					}
				}
				result = num;
			}
			return result;
		}
		protected virtual string CheckNumList(string str)
		{
			string result;
			if (str == "" || str == null)
			{
				result = string.Empty;
			}
			else
			{
				if (str.Contains(","))
				{
					string[] array = str.Split(new char[]
					{
						','
					});
					for (int i = 0; i < array.Length; i++)
					{
						if (array[i] == "")
						{
							result = string.Empty;
							return result;
						}
						try
						{
							int.Parse(array[i]);
						}
						catch
						{
							result = string.Empty;
							return result;
						}
					}
				}
				else
				{
					try
					{
						int.Parse(str);
					}
					catch
					{
						result = string.Empty;
						return result;
					}
				}
				result = str;
			}
			return result;
		}
		private bool IsNum(string str)
		{
			bool result;
			for (int i = 0; i < str.Length; i++)
			{
				if (str[i] < '0' || str[i] > '9')
				{
					result = false;
					return result;
				}
			}
			result = true;
			return result;
		}
		private static bool IsEmail(string s)
		{
			string pattern = "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
			return Regex.IsMatch(s, pattern);
		}
		private bool IsNumber(string strNumber)
		{
			bool result;
			if (!string.IsNullOrEmpty(strNumber))
			{
				try
				{
					double.Parse(strNumber);
				}
				catch
				{
					result = false;
					return result;
				}
				result = true;
			}
			else
			{
				result = false;
			}
			return result;
		}
		protected virtual decimal ToDecimal(string str)
		{
			decimal result;
			if (this.IsNumber(str))
			{
				result = Convert.ToDecimal(str);
			}
			else
			{
				result = 0m;
			}
			return result;
		}
		protected virtual bool IsDate(string value)
		{
			bool result;
			try
			{
				DateTime.Parse(value);
			}
			catch
			{
				result = false;
				return result;
			}
			result = true;
			return result;
		}
		private bool CheckChineaseName(string StrName)
		{
			return Regex.IsMatch(StrName, "[一-龥豈-鶴]");
		}
		protected virtual void WriteErrMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/ErrTitle");
			}
			if (ComeUrl != "")
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:gray; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='",
					ComeUrl,
					"'>确定</a></div></td></tr></table>"
				}));
			}
			else
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:gray; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='javascript:history.back();'>返回</a></div></td></tr></table>"
				}));
			}
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected virtual void WriteErrMsg2(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/ErrTitle");
			}
			if (ComeUrl != "")
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:gray; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='",
					ComeUrl,
					"'>确定</a></div></td></tr></table>"
				}));
			}
			else
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:gray; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='javascript:history.back();'>返回</a></div></td></tr></table>"
				}));
			}
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected virtual void WriteErrMsg3(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/ErrTitle");
			}
			if (ComeUrl != "")
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:red; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='",
					ComeUrl,
					"'>返回</a></div></td></tr></table>"
				}));
			}
			else
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:red; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='javascript:history.back();'>返回</a></div></td></tr></table>"
				}));
			}
			this.Finish();
			HttpContext.Current.Response.End();
		}
		protected virtual void WriteSuccessMsg(string errType, string msg, string ComeUrl)
		{
			if (errType == "")
			{
				errType = Language.Get("Common/SuccessTitle");
			}
			if (ComeUrl != "")
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:gray; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='",
					ComeUrl,
					"'>确定</a></div></td></tr></table>"
				}));
			}
			else
			{
				HttpContext.Current.Response.Write(string.Concat(new string[]
				{
					"<table align=\"center\" style='border:solid 1px gray;width:400px;height:300px:margin-left:auto;margin:right:auto;text-align:center; font-size:12px;'><tr style=\"background:gray; height:25px; color:white;\"><th>",
					errType,
					"</th></tr><tr><td style=\"height:60px;\">",
					msg,
					"<div><a href='javascript:history.back();'>返回</a></div></td></tr></table>"
				}));
			}
			this.Finish();
			HttpContext.Current.Response.End();
		}
		private string GetDomainName(string SiteHostName)
		{
			string result;
			if (SiteHostName.ToLower() != "localhost" && SiteHostName != "127.0.0.1" && SiteHostName.Contains("."))
			{
				string[] array = new string[]
				{
					".com.cn",
					".org.cn",
					".net.cn",
					".gov.cn",
					"edu.cn",
					".com",
					".net",
					".cn",
					".org",
					".mobi",
					".biz",
					".cc",
					".tv",
					".name",
					".info"
				};
				for (int i = 0; i < array.Length; i++)
				{
					int num = SiteHostName.LastIndexOf(array[i]);
					if (num > 0)
					{
						SiteHostName = SiteHostName.Remove(num);
						int num2 = SiteHostName.LastIndexOf(".");
						string text;
						if (num2 > 0)
						{
							text = SiteHostName.Substring(num2 + 1) + array[i];
						}
						else
						{
							text = SiteHostName + array[i];
						}
						result = text.ToLower();
						return result;
					}
				}
				result = SiteHostName.ToLower();
			}
			else
			{
				result = SiteHostName.ToLower();
			}
			return result;
		}
		protected virtual bool CheckValidateCode(string Str)
		{
			return this.Session["CheckCode"] != null && !string.IsNullOrEmpty(Str) && string.Compare(this.Session["CheckCode"].ToString(), Str, true) == 0;
		}
		private void Root_Error(object sender, EventArgs e)
		{
			this.Dispose();
		}
		public override void Dispose()
		{
			this.Finish();
			base.Dispose();
		}
		protected virtual DataTable GetQuestionList()
		{
			DataTable dataTable = new DataTable();
			dataTable.Columns.Add("Name");
			XmlDocument xmlDocument = new XmlDocument();
			xmlDocument.Load(Language.GetPath(AppSetings.Get("InstallDir")));
			XmlNode xmlNode = xmlDocument.DocumentElement.SelectSingleNode("PassPort/RegQuestionList");
			foreach (XmlNode xmlNode2 in xmlNode.ChildNodes)
			{
				dataTable.Rows.Add(new object[]
				{
					xmlNode2.InnerText
				});
			}
			return dataTable;
		}
	}
}
